package cn.liuxiany.alibaba.job.service.impl;

import cn.liuxiany.alibaba.job.entity.Order;
import cn.liuxiany.alibaba.job.mapper.OrderMapper;
import cn.liuxiany.alibaba.job.service.JobService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description jobService
 * @Author liuxiany
 * @Date 2023/11/09
 */
@Slf4j
@Service
public class JobServiceImpl implements JobService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void test(String name) {
        LambdaQueryWrapper<Order> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Order::getName, name);
        queryWrapper.last("limit 1");

        Order order = orderMapper.selectOne(queryWrapper);

        Gson gson = new Gson();
        log.info("order is {}", gson.toJson(order));

        if (order != null) {
            String myName = "jack_master" + System.currentTimeMillis();
            order.setName(myName);

            orderMapper.updateById(order);
        }
    }
}
